package com.baseframe.system.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baseframe.auth.utils.AuthUtil;
import com.baseframe.mybatis.utils.PageUtil;
import com.baseframe.system.entity.BaseNotice;
import com.baseframe.system.entity.request.BaseNoticeRequest;
import com.baseframe.system.entity.vo.BaseNoticeVO;
import com.baseframe.system.service.BaseNoticeService;
import com.baseframe.system.mapper.BaseNoticeMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**

* @description 针对表【base_notice】的数据库操作Service实现
* @createDate 2023-06-23 11:21:11
*/
@Service
@Slf4j
public class BaseNoticeServiceImpl extends ServiceImpl<BaseNoticeMapper, BaseNotice>
    implements BaseNoticeService{

    @Override
    public boolean addNotice(BaseNoticeRequest request) {
        BaseNotice baseNotice = new BaseNotice();
        baseNotice.setTheme(request.getTheme());
        baseNotice.setContent(request.getContent());
        baseNotice.setPublisher(AuthUtil.getUserId());

        log.info("notice:{}",baseNotice);

        return this.save(baseNotice);
    }

    @Override
    public boolean deleteById(Long id) {
        return this.removeById(id);
    }

    @Override
    public Page<BaseNoticeVO> noticePageList(Page<BaseNoticeVO> page, BaseNoticeRequest request) {
        PageUtil.selectCountPage(page);

        return this.getBaseMapper().getPage(page,request);
    }

    @Override
    public List<BaseNoticeVO> getNoticeByNew() {

        return this.getBaseMapper().getNoticeByNew();
    }
}




